<template>
	<view class="view_main">
		<view class="view1">
			<image src="/static/header.png"></image>
			<input v-model="form.username" placeholder="请输入用户名" />
			<input v-model="form.password" password class="uni-input" placeholder="请输入密码" />
			<button @click="login">登录</button>
		</view>
		<view class="view2">
			<navigator url="/pages/findPassword/findPassword">
				<text>忘记密码？</text>
			</navigator>
			<navigator url="/pages/register/register">
				<text>没有账号，去注册</text>
			</navigator>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					username: "",
					password: ""
				}
			};
		},
		methods: {
			login() {
				this.$.ajax({
					url: '/user/login',
					type: "POST",
					data: this.form,
					success: (res) => {
						uni.setStorageSync("loginToken", res);
						// 跳转到首页 navigateTo只能跳转到非tabBar页面
						// 而首页是tabBar页面，所以需要使用switchTab
						uni.switchTab({
							url: '/pages/index/index'
						})
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.view_main {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: center;

		.view1 {
			margin-top: 160rpx;
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;

			input {
				margin-top: 30rpx;
				width: 70%;
				border-bottom: 1px solid #ddd;
				padding: 20rpx 30rpx;
			}

			image {
				width: 250rpx;
				height: 250rpx;
			}

			button {
				width: 70%;
				margin-top: 30rpx;
				background-color: #00A2FF;
				color: white;
				box-shadow: 10rpx 10rpx 10rpx gray;
			}

			button:active {
				position: relative;
				top: 5rpx;
				left: 5rpx;
				box-shadow: 5rpx 5rpx 5rpx gray;
			}
		}

		.view2 {
			width: 100%;
			display: flex;
			justify-content: space-between;
			padding: 30rpx 50rpx;
			box-sizing: border-box;
			color: #808080;
			font-weight: 900;


			text:active {
				color: #00A2FF;
			}

		}
	}
</style>